import { ConditionList } from "~/search.match";
import { WithPasterList } from "~/view.with";
import { KeyAccumulatable } from "~/search";
import { PutMutiDto } from "~/rest";

import { ENUM_TON_NOTCH } from "@/river-stock/core.define";
import { TonOrder } from "./schema.order";
import { TonSku } from "./schema.sku";
import { TonSkuGateway } from "./dto.sku";

export type doTonSkuCreationDto = PutMutiDto<WithPasterList & TonSku> & { orderId: TonOrder["uuid32"] };
export type doTonSkuCreationRes = { updated: TonOrder; affected: TonSku[] };

export const TonSkuRpcGetSkuPath = `${TonSkuGateway.path}/getSku`;
export type getSkuRpcDto = { ids: TonSku["id"][] };

export const TonSkuRpcGetNotchStatPath = `${TonSkuGateway.path}/getNotchStat`;
export type getNotchStatRpcDto = { type: ENUM_TON_NOTCH; key: KeyAccumulatable<TonSku>; condis: ConditionList<TonSku> };

export const TonSkuRpcPutPurchasePath = `${TonSkuGateway.path}/putPurchaseSync`;
export type putPurchaseRpcDto = doTonSkuCreationDto & { amountTaxRate?: number };

export const TonSkuRpcPostPurchasePath = `${TonSkuGateway.path}/postPurchaseSync`;
export type postPurchaseRpcDto = doTonSkuCreationDto;

export const TonSkuRpcPutAdjustPath = `${TonSkuGateway.path}/putAdjustSync`;
export type putAdjustRpcDto = doTonSkuCreationDto;

export const TonSkuRpcPutProcessPath = `${TonSkuGateway.path}/putProcessSync`;
export type putProcessRpcDto = doTonSkuCreationDto;

export const TonSkuRpcPostProcessPath = `${TonSkuGateway.path}/postProcessSync`;
export type postProcessRpcDto = doTonSkuCreationDto;

export const TonSkuRpcPutSalePath = `${TonSkuGateway.path}/putSaleSync`;
export type putSaleRpcDto = doTonSkuCreationDto & { amountTaxRate?: number };

export const TonSkuRpcPostSalePath = `${TonSkuGateway.path}/postSaleSync`;
export type postSaleRpcDto = doTonSkuCreationDto;

export const TonSkuRpcPutSaleReturnPath = `${TonSkuGateway.path}/putSaleReturnSync`;
export type putSaleReturnRpcDto = doTonSkuCreationDto & { amountTaxRate?: number };

export const TonSkuRpcPostSaleReturnPath = `${TonSkuGateway.path}/postSaleReturnSync`;
export type postSaleReturnRpcDto = doTonSkuCreationDto;

export interface TonSkuReadRpcInterface<T> {
  getSku(dto: T & getSkuRpcDto): Promise<{ entityLs: TonSku[] }>;
  getNotchStat(dto: T & getNotchStatRpcDto): Promise<{ total: number }>;
}

export interface TonSkuWriteRpcPurchaseInterface<T> {
  putPurchaseSync(dto: T & putPurchaseRpcDto): Promise<doTonSkuCreationRes>;
  postPurchaseSync(dto: T & postPurchaseRpcDto): Promise<doTonSkuCreationRes>;
}

export interface TonSkuWriteRpcAdjustInterface<T> {
  putAdjustSync(dto: T & putAdjustRpcDto): Promise<doTonSkuCreationRes>;
}

export interface TonSkuWriteRpcProcessInterface<T> {
  putProcessSync(dto: T & putProcessRpcDto): Promise<doTonSkuCreationRes>;
  postProcessSync(dto: T & postProcessRpcDto): Promise<doTonSkuCreationRes>;
}

export interface TonSkuWriteRpcSaleInterface<T> {
  putSaleSync(dto: T & putSaleRpcDto): Promise<doTonSkuCreationRes>;
  postSaleSync(dto: T & postSaleRpcDto): Promise<doTonSkuCreationRes>;
}

export interface TonSkuWriteRpcSaleReturnInterface<T> {
  putSaleReturnSync(dto: T & putSaleReturnRpcDto): Promise<doTonSkuCreationRes>;
  postSaleReturnSync(dto: T & postSaleReturnRpcDto): Promise<doTonSkuCreationRes>;
}
